package com.legsem.jhosync;

import com.legsem.jhosync.face.PartitionType;
import com.legsem.jhosync.face.SourceAdapter;

/**
 * Holds the configuration for a developer's custom source.
 * 
 */
public class SourceConfig {

    /** Administrator user ID. */
    public static final String ADMIN_LOGIN = "jhoadmin";

    /** User ID for shared master documents (partition_type = app). */
    public static final String SHARED_LOGIN = "__shared__";

    /** The source name. */
    private String name;

    /**
     * The time (in seconds) to wait before considering the data is stale and
     * needs to be fetched from the backend.
     */
    private int pollInterval;

    /** Master doc held per user or shared. */
    private PartitionType partitionType;

    /** The source implementation class. */
    private Class < ? extends SourceAdapter > sourceClass;

    public String getName() {
        return name;
    }

    /**
     * @return true if this is a shared source (master doc is shared by all
     *         users)
     */
    public boolean isShared() {
        return (getPartitionType() == PartitionType.APP);
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPollInterval() {
        return pollInterval;
    }

    public void setPollInterval(int poll_interval) {
        this.pollInterval = poll_interval;
    }

    public Class < ? extends SourceAdapter > getSourceClass() {
        return sourceClass;
    }

    public void setSourceClass(Class < ? extends SourceAdapter > sourceClass) {
        this.sourceClass = sourceClass;
    }

    public PartitionType getPartitionType() {
        return partitionType;
    }

    public void setPartitionType(PartitionType partitionType) {
        this.partitionType = partitionType;
    }

    @Override
    public String toString() {
        return "SourceConfig [name=" + name + ", pollInterval=" + pollInterval
                + ", partitionType=" + partitionType + ", sourceClass="
                + sourceClass + "]";
    }

}
